import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    list:[],
   lists:[]
  },
  mutations: {
    arr(state,i){
      console.log(i);
      state.list=i 
    },
    add(state,i){
      let flag = false
      state.lists.forEach((item) => {
        if (item.id == i.id) {
          flag = true
          alert('书架中已有此书!!')
        }
      })
      if (flag == false) {
        state.lists.push(i)
      }
    },
    dian(state,i){
      state.lists.forEach(item=>{
        if(item.id==i.id){
          item.state =1
        }
      })
    },
    dians(state,i){
      state.lists.forEach(item=>{
        if(item.id==i.id){
          item.state =0
        }
      })
    },
    remove(state,i){
      state.lists.forEach((item,index)=>{
        if(item.id==i.id){
          state.lists.splice(index,1)
        }
    })
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
})
